import grpc
from concurrent import futures

from RPC.grpc.grpc_hello.proto import helloworld_pb2_grpc, helloworld_pb2


class Greeter(helloworld_pb2_grpc.GreeterServicer):
    def SayHello(self, request, context):
        return helloworld_pb2.HelloReply(message=f"你好,{request.name}")


if __name__ == '__main__':
    # 实例化server
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))  # 设置线程池
    # 注册逻辑到server
    helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
    # 启动server
    server.add_insecure_port('0.0.0.0:8080')
    print('listen to 8080...')
    server.start()
    server.wait_for_termination()
